package icu.ikuns;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author： Kimariyb
 * @Date：2022/05/22/14:25
 * @Description：
 */
public class CalCircle extends HttpServlet {
    public CalCircle() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String radius = req.getParameter("radius");
        double r = 0;
        if (radius == null) {
            radius = "0";
            try {
                r = Double.parseDouble(radius);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            resp.setCharacterEncoding("utf-8");
            PrintWriter out = resp.getWriter();
            out.print("<html><head></head><body>");
            out.print("面积是：" + 3.14159 * r * r);
            out.print("</body></html>");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
